package com.qf.dao;

import com.qf.pojo.Orders;
import com.qf.util.DataSourceUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * @author 千锋健哥
 */
public class OrderDaoImpl implements OrderDao{

    private QueryRunner queryRunner = new QueryRunner(DataSourceUtil.getDataSource());

    @Override
    public void insertOrder(Orders orders) {
        try {
            String sql = "insert into tb_order (id, uid, money, `status`, time, aid) values(?, ?, ?, ? ,?, ?)";
            queryRunner.update(sql, orders.getId(), orders.getUid(), orders.getMoney(),
                    orders.getStatus(), orders.getTime(), orders.getAid());
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    public List<Orders> findByUid(Integer uid) {
        try {
            String sql = "select * from tb_order where uid=?";
            List<Orders> list = queryRunner.query(sql, new BeanListHandler<Orders>(Orders.class), uid);
            return list;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

}
